/**
 * @file Buffer.cpp
 * @author your name (you@domain.com)
 * @brief
 * @version 0.1
 * @date 2022-04-05
 *
 * @copyright Copyright (c) 2022
 *
 */

#pragma once

#include "Condition.h"
#include "MutexLock.h"
#include "Noncopyable.h"
#include <functional>
#include <queue>

namespace wd
{

class TaskQueue : Noncopyable
{
  public:
    typedef std::function<void()> Task;
    TaskQueue(size_t size);

    void push(Task task);
    Task pop();

    bool full();
    bool empty();

    void wakeup_empty();
    void set_flag(bool flag);

  private:
    MutexLock mutex_;
    Condition notFull_;
    Condition notEmpty_;
    size_t size_;
    std::queue<Task> que_;
    bool flag_;
};

} // end of namespace wd
